package com.itheima.service.empl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.bean.DishFlavor;
import com.itheima.dao.FlavorDao;
import com.itheima.service.FlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class FlavorServiceImpl implements FlavorService {

    @Autowired
    private FlavorDao flavorDao;
    /**
     * 添加菜品口味
     *
     * @param dishFlavor
     * @return
     */
    @Override
    public int add(DishFlavor dishFlavor) {

        return flavorDao.insert(dishFlavor);
    }

    /**
     * 通过dish Id查找
     *
     * @param dishId
     * @return
     */
    @Override
    public List<DishFlavor> findByDishId(Long dishId) {
        LambdaQueryWrapper<DishFlavor> qw = new LambdaQueryWrapper<>();
        qw.eq(DishFlavor::getDishId,dishId);
        return flavorDao.selectList(qw);
    }

    /**
     * 修改菜品口味
     *
     * @param dishFlavor
     * @return
     */
    @Override
    public int update(DishFlavor dishFlavor) {
        LambdaQueryWrapper<DishFlavor> qw = new LambdaQueryWrapper<>();
        qw.eq(DishFlavor::getDishId,dishFlavor.getDishId());
        return flavorDao.update(dishFlavor,qw);
    }

    /**
     * 通过dish Id 删除
     *
     * @param dishId
     * @return
     */
    @Override
    public int deleteByDishId(Long dishId) {
        LambdaQueryWrapper<DishFlavor> qw = new LambdaQueryWrapper<>();
        qw.eq(DishFlavor::getDishId,dishId);
        return flavorDao.delete(qw);
    }
}
